import { NavigateService } from './../../services/navigate';
import { StoreSvr } from './../../services/store';
import { MessageBoxService, MessageResult, GrowlMessageType } from './../../components/messageBox';
import { DataContext } from './../../utils/@tiny/indexedDB/dataContext';
import { ConfigSvr } from './../../services/config';
import { Component } from '@angular/core';

@Component({
  styleUrls: ['./index.scss'],
  template: `
    <div class="resetsetup-container title">
        <ul>
            <li *ngFor="let data of terminalInfo">{{data.title+": "+data.value}}</li>
        </ul>
        <div class="reset">
            <p><i class="material-icons">error</i></p>
            <p class="warn">警告：重置将删除所有数据</p>
            <p class="tooltip content">通常仅当需要更换当前终端的店铺或终端名称，以及不在使用当前终端时，才需要使用此功能。</p>
            <button  (click)="resetTerminal()">重新设置终端</button>
        </div>
    </div>
  `
})
export class ResetSetup {
  private terminalInfo: Array<any>;
  constructor(private configSvr: ConfigSvr, private storeSvr: StoreSvr, private navSvr: NavigateService) {
    this.terminalInfo = this.configSvr.currentTerminalInfo;
  }
  async resetTerminal() {
    try {
      let result = await MessageBoxService.current.Show("提示", "确认清除终端数据？");
      if (result == MessageResult.Ok) {
        // await this.storeSvr.cancelTerminal();
        // await this.storeSvr.deleteDevice(this.storeSvr.currentDevice);
        await this.storeSvr.forbiddenDevice();
        this.navSvr.navigate(["initialization/welcome"])
        this.configSvr.resetTerminal();
      }
    } catch (error) {
      MessageBoxService.current.Growl(GrowlMessageType.Error, "绑定终端出错", error.message || error);
    }
  }
}